﻿Imports Aricie.DNN.Modules.LuceneSearch.ModuleProviders
Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.Services.Search
Imports DotNetNuke.Common.Utilities
Imports Aricie.DNN.Modules.LuceneSearch.Business
Imports System.Linq
Imports System.Data
Imports PackFlash.DNN.Modules.Publishing
Imports PackFlash.DNN.Modules.Publishing.DAL


Namespace Aricie.DNN.Modules.LuceneSearch.ModuleProviders


    Public Class PackFlashVideoProvider
        Implements ILuceneSearchableUpgrade


        Public Sub UpgradeSearchItem(ByVal portalId As Integer, ByRef searchItem As Business.LuceneSearchItemInfo) Implements ILuceneSearchableUpgrade.UpgradeSearchItem
            Dim CA As New ControllerArticle()
            searchItem.ItemId = Integer.Parse(searchItem.SearchKey) ' vérifier searchItem.searchItemID
            Dim IA As InfoArticle = CA.GetArticle(searchItem.ItemId, False, portalId)


            If (IA IsNot Nothing) Then

                Select Case IA.MediaType
                    Case 4
                        ' type video
                        Dim CAR As New ControllerArticleRoles()
                        Dim CAC As New ControllerArticleCategory()
                        Dim CAT As New ControllerArticleTag()
                        Dim CAI As New ControllerArticleIssue()

                        For Each IAR As InfoArticleRoles In CAR.GetAllRolesForArticle(IA.ArticleID)
                            searchItem.ItemViewRoleIds.Add(IAR.RoleID)
                        Next
                        For Each IAC As InfoArticleCategory In CAC.GetArticleCategoriesByArticleID(IA.ArticleID)
                            searchItem.ContentTaxonomy.Add(IAC.CategoryName)
                        Next
                        For Each IAT As InfoArticleTag In CAT.GetArticleTagsByArticleID(IA.ArticleID)
                            searchItem.ContentTaxonomy.Add(IAT.TagName)
                        Next
                        For Each IAI As InfoArticleIssue In CAI.GetArticleIssuesByArticleID(IA.ArticleID)
                            searchItem.ContentTaxonomy.Add(IAI.IssueName)
                        Next

                        For Each SEOTag As String In IA.SEOKeywords.Split(New String() {","}, StringSplitOptions.RemoveEmptyEntries)
                            searchItem.ContentTaxonomy.Add(SEOTag)
                        Next

                        searchItem.CanBeReturnedBySearch = IA.Approved
                        searchItem.ReturnedBySearchWindowStart = IA.PublishDate
                        searchItem.ReturnedBySearchWindowEnd = IA.ExpireDate
                        
                        searchItem.ItemType = "Video"

                    Case Else
                        ' rien d'autre pour l'instant, on ne gère que la vidéo
                End Select
            End If

        End Sub


    End Class

End Namespace